﻿package app.view.components.guiDima.switchContent 
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import gs.TweenLite;
	import org.casalib.display.CasaSprite;
	//import org.casalib.display.CasaSprite;
	/**
	 * Базовый класс для все переключаемых контентов
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class ContentBaseD extends CasaSprite
	{
		protected var _bgd:Shape;
		protected var _contentWidth:Number;
		protected var _contentHeight:Number;
		
		//	public
		// идентификатор
		public var id:String;
		// данные
		protected var _data:Object;
		//	private
		// настройки скрытия/показа
		private var _openDuration:Number = 0.4;
		private var _closeDuration:Number = 0.4;
		//	const
		// отстыпы от BGD
		protected var _gapLeft:Number = 10;
		protected var _gapRight:Number = 10;
		protected var _gapTop:Number = 10;
		protected var _gapBottom:Number = 10;
		
		//	CONSTRUCTOR
		public function ContentBaseD(w:Number,h:Number) 
		{
			super();
			_contentWidth = w;
			_contentHeight = h;
			
			init();
		}
		
		//	METHODS
		//	private
		public function init():void
		{
			build();
		}
		
		//	public
		public function build():void
		{
			//trace('-------',_contentWidth,_contentHeight);
			
			_bgd = new Shape();
			_bgd.alpha = 0;
			_bgd.graphics.beginFill(0xffff56,0.5);
			_bgd.graphics.drawRect(0, 0, _contentWidth, _contentHeight);
			_bgd.graphics.endFill();
			addChild(_bgd);
		}
		
		public function open(immediate:Boolean = false):void 
		{
			if ( immediate ) 
			{
				alpha = 1;
				mouseChildren = mouseEnabled = true;
				return;
			};
			TweenLite.to ( this, _openDuration, { alpha : 1 } );
		}
		
		public function close(immediate:Boolean = false):void 
		{
			if ( immediate ) 
			{
				alpha = 0;
				mouseChildren = mouseEnabled = false;
				return;
			};
			TweenLite.to ( this, _closeDuration, { alpha : 0 } );
		};
		
		override public function destroy():void 
		{
			mouseChildren = mouseEnabled = false;
			TweenLite.to ( this, _closeDuration, { alpha : 0, onComplete: onDestroy } );			
		};
		
		public function onDestroy():void
		{
			try 
			{
				removeChild(_bgd);
			}catch (err:Error)
			{
				
			}
			
			
			super.destroy();
		}
		
		protected function setBoundsContent(w:Number,h:Number):void
		{
			
			
			//build();
			
			
		}
		
		protected function updateDisplayList(sw:Number,sh:Number):void
		{
			
		}
		//	----------------------------------------------------------------------------------
		
		//	GETTERS/SETTERS
		public function get data():Object { return _data; };
		
		public function set data(value:Object):void 
		{
			//SectionVO
			_data = value;
		};
		//	----------------------------------------------------------------------------------
		
		//	HANDLERS
		
	}

}